from pydantic import BaseModel, Field, validator
from typing import Optional, Literal
from datetime import datetime
from enum import Enum

# 枚举类型定义
class QuestionType(str, Enum):
    CHOICE = 'choice'
    FILL = 'fill'
    SHORT = 'short'

# 请求模型 - 用于创建和更新
class QuestionCreate(BaseModel):
    content: str = Field(..., min_length=1, description="问题内容")
    answer: str = Field(..., min_length=1, description="问题答案")
    question_type: QuestionType = Field(..., description="问题类型")
    difficulty: int = Field(..., ge=1, le=10, description="难度系数(1-10)")
    major: Optional[str] = Field(None, max_length=50, description="专业")
    course: str = Field(..., max_length=50, description="课程")
    subject: Optional[str] = Field(None, max_length=50, description="科目")
    analysis: Optional[str] = Field(None, description="解析")
    question_time: int = Field(..., ge=1, description="答题时间(秒)")

class QuestionUpdate(BaseModel):
    content: Optional[str] = Field(None, min_length=1, description="问题内容")
    answer: Optional[str] = Field(None, min_length=1, description="问题答案")
    question_type: Optional[QuestionType] = Field(None, description="问题类型")
    difficulty: Optional[int] = Field(None, ge=1, le=10, description="难度系数(1-10)")
    major: Optional[str] = Field(None, max_length=50, description="专业")
    course: Optional[str] = Field(None, max_length=50, description="课程")
    subject: Optional[str] = Field(None, max_length=50, description="科目")
    analysis: Optional[str] = Field(None, description="解析")
    question_time: Optional[int] = Field(None, ge=1, description="答题时间(秒)")

# 响应模型 - 用于返回数据
class QuestionResponse(BaseModel):
    id: int
    content: str
    answer: str
    question_type: QuestionType
    difficulty: int
    major: Optional[str]
    course: str
    subject: Optional[str]
    analysis: Optional[str]
    question_time: int
    created_at: datetime
    updated_at: datetime

    class Config:
        orm_mode = True

# 简化响应模型 - 用于列表展示
class QuestionSimpleResponse(BaseModel):
    id: int
    content: str
    question_type: QuestionType
    difficulty: int
    course: str
    question_time: int

    class Config:
        orm_mode = True